﻿package app.view 
{
	import app.model.DataProxy;
	import flash.display.MovieClip;
    import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
    import org.puremvc.as3.patterns.mediator.Mediator;
	import app.ApplicationFacade;
	/**
	* Author lzyy
    * Email:healdream@gmail.com
    * Blog:http://lab.lzyy.name/blog
	*/
	public class IntroMediator extends Mediator implements IMediator
	{
		public static const NAME:String = 'IntroMediator';
		private var _titleArr:Array = new Array();
		private var _introArr:Array = new Array();
		public function IntroMediator(vc) 
		{
			super(NAME, vc);
			
		}
		
		override public function listNotificationInterests():Array 
        {
            return [ApplicationFacade.IMG_CHANGED];            
        }

        override public function handleNotification( note:INotification ):void
        {
            switch(note.getName())
            {
                case ApplicationFacade.IMG_CHANGED:
                    var data = note.getBody();
					_setData();
                    _changeText(data.index);
                    break;
            }
        }
		
		private function _changeText(n)
		{
			introTxt.title.htmlText = "<b>"+_titleArr[n]+"</b>";
			introTxt.intro.text = _introArr[n];
			//trace(_titleArr);
		}
		
		private function _setData()
		{
			var dp:DataProxy = facade.retrieveProxy(DataProxy.NAME) as DataProxy;
			var data:Object = dp.getData();
			_titleArr = data.title;
			_introArr = data.intro;
		}
		
		private function get introTxt()
		{
			return viewComponent as MovieClip;
		}
	}
	
}